package com.zut.service.impl;

import com.zut.dao.ShopDao;
import com.zut.dao.impl.ShopDaoImpl;
import com.zut.pojo.Shop;
import com.zut.service.ShopService;
import com.zut.vo.ShopVo;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/12 13:19
 * @desc
 */
public class ShopServiceImpl implements ShopService {
    private ShopDao shopDao = new ShopDaoImpl();
    @Override
    public Integer addShop(Shop shop) {
        return shopDao.insert(shop);
    }

    @Override
    public List<ShopVo> selectById(String businessId) {
        List<Shop> shops = shopDao.selectById(businessId);
        List<ShopVo> shopVos = new ArrayList<>();
        for (Shop shop : shops) {
            ShopVo shopVo = new ShopVo();
            BeanUtils.copyProperties(shop,shopVo);

            String categoryName = shopDao.getCategoryName(shop.getShopCategoryId());
            shopVo.setCategoryName(categoryName);
            shopVos.add(shopVo);
        }
        return shopVos;
    }

    @Override
    public Integer deleteShopById(int i) {
        return shopDao.deleteById(i);
    }

    @Override
    public Integer updateById(Shop shop) {
        return shopDao.updateById(shop);
    }


}
